package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>,SelectByIdListMapper<Brand,Long> {

    /**
     * 新增商品分类和品牌中间表数据
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return
     */
    @Insert("insert into tb_category_brand (category_id, brand_id) values(#{cid},#{bid})")
    void insertCategoryBrand(@Param("cid") Long cid,@Param("bid") Long bid);

    @Delete("delete from tb_category_brand where brand_Id=#{id}")
    void deleteCategoryBrandById(@Param("id") Long id);

    @Select("select * from tb_brand where id in (select brand_id from tb_category_brand where category_id =#{cid})")
    List<Brand> queryBrandsByCid(@Param("cid")Long cid);
}